﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Kailua.net.windward.utils.ado.SPList.custom
{
    /// <summary>
    /// A data adapter for SharePoint list data providers.
    /// </summary>
    public class SPListDataAdapter : IDataAdapter
    {
        private SPListCommand selectCommand;

        /// <summary>
        /// Gets or sets the select command.
        /// </summary>
        public SPListCommand SelectCommand
        {
            get { return selectCommand; }
            set { selectCommand = value; }
        }

        #region IDataAdapter Members

        /// <summary>
        /// Executes the SelectCommand and fills the specified DataSet with the query result.
        /// </summary>
        /// <param name="dataSet"></param>
        /// <returns>the number of rows in the query result</returns>
        public int Fill(DataSet dataSet)
        {
            DataTable cmdDt = SelectCommand.executeAndCreateDataTable();
            dataSet.Tables.Add(cmdDt);
            return cmdDt.Rows.Count;
        }

        /// <summary>
        /// Not supported.
        /// </summary>
        /// <param name="dataSet"></param>
        /// <param name="schemaType"></param>
        /// <returns></returns>
        public DataTable[] FillSchema(DataSet dataSet, SchemaType schemaType)
        {
            throw new NotSupportedException();
        }

        /// <summary>
        /// Not supported.
        /// </summary>
        /// <returns></returns>
        public IDataParameter[] GetFillParameters()
        {
            throw new NotSupportedException();
        }

        /// <summary>
        /// Not supported.
        /// </summary>
        public MissingMappingAction MissingMappingAction
        {
            get
            {
                throw new NotSupportedException();
            }
            set
            {
                throw new NotSupportedException();
            }
        }

        /// <summary>
        /// Not supported.
        /// </summary>
        public MissingSchemaAction MissingSchemaAction
        {
            get
            {
                throw new NotSupportedException();
            }
            set
            {
                throw new NotSupportedException();
            }
        }

        /// <summary>
        /// Not supported
        /// </summary>
        public ITableMappingCollection TableMappings
        {
            get { throw new NotSupportedException(); }
        }

        /// <summary>
        /// Not supported
        /// </summary>
        /// <param name="dataSet"></param>
        /// <returns></returns>
        public int Update(DataSet dataSet)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
